package com.test.service.impl;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.test.domain.Company;
import com.test.domain.User;
import com.test.mapper.CompanyMapper;
import com.test.mapper.UserMapper;
import com.test.service.CompanyService;

import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;
@Service
public class CompanyServiceImpl extends BaseServiceImpl<Company> implements CompanyService  {
	@Autowired
	private CompanyMapper companyMapper;

	@Override
	public Company findCompanyByCompanyName(String companyName) {
		// TODO Auto-generated method stub
		return this.companyMapper.getCompanyByCompanyName(companyName);
	}

	@Override
	public void deleteBatchByIds(String[] idsStr) {
		// TODO Auto-generated method stub
		this.companyMapper.deleteBatchByIds(idsStr);
		
	}
	@Override
	public List<Company> getCompanyList(){
		Example cond = new Example(Company.class);
		List<Company> list = this.getList();      
		return list;
	}

	@Override
	public PageInfo<Company> getListByPage(int currentNum, int pageSize, String name) {
		// TODO Auto-generated method stub
		Example cond = new Example(Company.class);
        if (!StringUtils.isEmpty(name)) {
        	try {
				name = new String(name.getBytes("utf-8"),"utf-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
            cond.createCriteria().andLike("companyName","%"+ name+"%");
        }
		
        PageHelper.startPage(currentNum, pageSize);
        List<Company> list = this.companyMapper.selectByExample(cond);
		return new PageInfo<Company>(list);
	}

	@Override
	protected Mapper<Company> getMapper() {
		// TODO Auto-generated method stub
		return this.companyMapper;
	}
	
}
